package edu.stanford.bmir.protege.web.client.ui.ontology.stkos.enricher.statistical;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasEnabled;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;

import edu.stanford.bmir.protege.web.client.project.Project;
import edu.stanford.bmir.protege.web.client.rpc.stkosutil.enricher.EnrichmentResult;
import edu.stanford.bmir.protege.web.client.rpc.stkosutil.enricher.actions.CreateTriplesResult;

public class StkosEnricherStatisticalEditorView extends Composite implements
		IsWidget, HasEnabled {

	interface StkosEnricherStatisticalEditorViewUiBinder extends
			UiBinder<HTMLPanel, StkosEnricherStatisticalEditorView> {
	}

	private static StkosEnricherStatisticalEditorViewUiBinder ourUiBinder = GWT
			.create(StkosEnricherStatisticalEditorViewUiBinder.class);

	private Project project;

	/** 类总数 */
	@UiField
	protected Label classCount;
	/** 原始类数 */
	@UiField
	protected Label originalClassNumber;
	/** 丰富的类数 */
	@UiField
	protected Label enricherClassNumber;

	/** 属性总数 */
	@UiField
	protected Label propertyCount;
	/** 原始属性数 */
	@UiField
	protected Label originalPropertyNumber;
	/** 丰富的属性数 */
	@UiField
	protected Label enricherPropertyNumber;

	public StkosEnricherStatisticalEditorView(Project project) {
		this.project = project;
		HTMLPanel rootElement = ourUiBinder.createAndBindUi(this);
		initWidget(rootElement);
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	@Override
	public void setEnabled(boolean enabled) {
	}

	public void setEnrichmentResult(EnrichmentResult result) {
		int totalClassNumber = 0, originalClassNumber = 0, enrichedClassNumber = 0, totalPropertyNumber = 0, originalPropertyNumber = 0, enrichedPropertyNumber = 0;
		if(result!=null){
			totalClassNumber = result.getTotalClassNumber();
			originalClassNumber = result.getOriginalClassNumber();
			enrichedClassNumber = result.getEnrichedClassNumber();
			
			totalPropertyNumber = result.getTotalPropertyNumber();
			originalPropertyNumber = result.getOriginalPropertyNumber();
			enrichedPropertyNumber = result.getEnrichedPropertyNumber();
		}
		this.classCount.setText(String.valueOf(totalClassNumber));
		this.originalClassNumber.setText(String.valueOf(originalClassNumber));
		this.enricherClassNumber.setText(String.valueOf(enrichedClassNumber));
		
		this.propertyCount.setText(String.valueOf(totalPropertyNumber));
		this.originalPropertyNumber.setText(String.valueOf(originalPropertyNumber));
		this.enricherPropertyNumber.setText(String.valueOf(enrichedPropertyNumber));
	}
	
	public void setCreateTriplesResult(CreateTriplesResult result) {
		EnrichmentResult result2 = null;
		try{
			result2 = result.getEnrichmentResult();
		} catch(Exception e){
		}
		setEnrichmentResult(result2);
	}
}
